<?php
	//添加权限角色
	require '../biz/backend.php';

	class action extends backend
	{
		var $get_privilege_id = 31;
		var $post_privilege_id = 31;

		function do_get()
		{
			$privilege = load( 'biz.privilege' );
			$template = load( 'template', array( 'domain'=>'tpl.admin' ) );
			$template->assign( 'privilege_array', $privilege->dict() );
			$template->assign( 'reference', isset( $this->input['reference'] ) ? urldecode( $this->input['reference'] ) : config( 'server.HTTP_REFERER' ) );
			echo $template->parse( 'add_role.php' );
		}

		function do_post()
		{
			$url = isset( $this->input['reference'] ) ? $this->input['reference'] : config( 'domain.admin' ) . 'list_role.php';
			unset( $this->input['reference'] );

			$role = load( 'biz.role' );
			$result = $role->add( $this->input );

			if ( $result['success'] )
			{
				$this->prompt( '成功创建角色', array( array( 'url' => config( 'domain.admin' ) . 'add_role.php?reference=' . urlencode( $url ), 'name' => '继续创建角色' ), array( 'url' => $url, 'name' => '返回角色列表' ) ) );
			}
			else
			{
				$this->prompt( '创建角色失败', $this->transform( $result['message'], config( 'server.HTTP_REFERER' ) ) );
			}
		}
	}

	$action = new action();
	$action->run();
?>